﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Web.UI;

namespace Components.Data.UI.Controls.ControlBuilders
{
  class ServerControlBuilder : IControlBuilder
  {
    #region IControlBuilder Members

    public System.Web.UI.Control Build(ControlBindingArgs args)
    {
      String assemblyName = args["AssemblyName"];
      Assembly assembly = Assembly.Load(assemblyName);

      if (assembly == null)
        return null;

      String typeName = args["TypeName"];
      Type type = assembly.GetType(typeName);

      if (type == null)
        return null;

      Object obj = Activator.CreateInstance(type);

      if (!(obj is Control))
        return null;

      return (Control)obj;
    }

    #endregion
  }
}